from time import sleep

from selenium.webdriver.support.wait import WebDriverWait

from base_page.basepage import BasePage

import allure

# 对象层
from config import log


class HomoPage(BasePage):
    def __init__(self, type="app"):
        super().__init__(type)
        self.home_jz = ('xpath', '//*[text() = "组织机构"]')  # 获取首页组织机构
        self.staff = ('xpath', '//*[text() = "员工认证"]')  # 获取首页员工认证
        self.cop = ('xpath', '//*[text() = "所属公司"]')  # 所属机构公司
        self.cop_rs = ("css", "div.am-picker-col-item.am-picker-col-item-selected ")  # 机构公司
        self.exit = ('xpath', '//*[text() = "取消"]')
        self.yes = ('xpath', '//*[text() = "确定"]')
        self.home_wallet = ('xpath', '//*[text() = "人保钱包"]')
        self.home = ()

    # 获取首页模块按钮
    @allure.step("首页")
    def find_home(self):
        return self.find_element_if("xpath", '//*[@id="app-root"]/div/div/div[6]/div[1]/div/div[2]/div/div[1]')
        # return self.driver.find_elements_by_css_selector(".am-tab-bar-tab-title")[0]

    # 获取首页---员工认证
    @allure.step('员工认证')
    def find_home_staff(self):
        return self.base_find_element(self.staff)

    # 获取首页组织机构
    @allure.step('组织机构')
    def find_home_jz(self):
        return self.base_find_element(self.home_jz)

    # 获取首页人保钱包
    @allure.step('(首页)人保钱包==钱包按钮')
    def find_home_wallet(self):
        return self.base_find_element(self.home_wallet)

    # 获取所属公司按钮
    @allure.step('所属公司')
    def find_cop(self):
        return self.base_find_element(self.cop)

    # 所属公司--中国人寿
    def find_cop_rs(self):
        return self.base_find_element(self.cop_rs)

    # 取消
    def find_exit(self):
        return self.find_element(self.exit)

    # 确定
    def find_yes(self):
        return self.find_element(self.yes)


# 操作层


class HomeHandle(object):
    def __init__(self):
        self.page = HomoPage()

    def click_home(self):
        self.page.find_home().click()

    def click_home_staff(self):
        self.page.find_home_staff().click()

    def click_cop(self):
        self.page.find_cop.click()

    def click_exit(self):
        self.page.find_exit().click()

    def click_yes(self):
        self.page.find_yes().click()

    def click_home_jz(self):
        self.page.find_home_jz().click()


# 逻辑层
class HomeProxy(object):
    def __init__(self):
        self.handle = HomeHandle()
        self.page = HomoPage()

    def home_staff(self):
        log.info("点击首页")

        self.handle.click_home()
        log.info("点击首页员工认证")
        self.handle.click_home_staff()
        log.info("点击所属公司")
        self.handle.click_cop()


